from time import sleep

from selenium import webdriver


driver = None


def login(username, password):
    global driver
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("http://beike.zxxk.com/index.html#/")

    # 多窗口切换
    driver.switch_to.frame('frame')  # 切换iframe

    driver.find_element_by_id('username').send_keys(username)
    driver.find_element_by_name("password").send_keys(password)
    driver.find_element_by_id('CommonLogin').click()


def logout():
    try:
        driver.find_element_by_css_selector('.bk-span-btn.logout').click()
        sleep(3)
    except Exception as e:
        print(e)
    finally:
        driver.quit()

